package com.douqu.game.core.config.task;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * @author: Gavin.
 * Description:
 * Date: 2017/10/24 0024 下午 7:05
 * Huan Yu Copyright (c) 2017 All Rights Reserved.
 */
public class GrowUpBoxConfig extends GameObject {

    public String boxIcon;
    /**成长值*/
    public int growthValue;
    /**道具掉落配置*/
    public CommonData[] props;
    /**资源掉落配置*/
    public CommonData[] assets;
    /**卡片掉落配置*/
    public CommonData[] cards;
    /**争霸赛杀人得分倍率*/
    public int  hegemonyScore;

    @Override
    public boolean check() {
        if(props == null)
        {
            LogUtils.error("GrowUpBox check props is null -> id:" + id + " name:" + name);
            return false;
        }

        if(assets == null)
        {
            LogUtils.error("GrowUpBox check assets is null -> id:" + id + " name:" + name);
            return false;
        }

        if(cards == null)
        {
            LogUtils.error("GrowUpBox check cards is null -> id:" + id + " name:" + name);
            return false;
        }
        return true;
    }

    public GoodsData[] getGoodsDataAry()
    {
        GoodsData[] ary = new GoodsData[props.length+assets.length+cards.length];
        int i = 0;
        for(CommonData commonData : props)
        {
            ary[i++] = new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_PROPS_VALUE, commonData.id, commonData.value);
        }
        for(CommonData commonData : assets)
        {
            ary[i++] = new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_ASSETS_VALUE, commonData.id, commonData.value);
        }
        for(CommonData commonData : cards)
        {
            ary[i++] = new GoodsData(SGCommonProto.E_GOODS_TYPE.GOODS_TYPE_CARDS_VALUE, commonData.id, commonData.value);
        }
        return ary;
    }

    @Override
    public boolean setVariable(String key, String value)
    {
        if("props".equals(key))
        {
            props = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(props, this.getClass(), key, DataFactory.PROP_KEY, id);
        }
        else if("assets".equals(key))
        {
            assets = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(assets, this.getClass(), key, DataFactory.ASSET_KEY, id);
        }
        else if("cards".equals(key))
        {
            cards = LoadUtils.loadCommonDataToArray(key, value);
            return LoadUtils.checkCommonData(cards, this.getClass(), key, DataFactory.CARD_KEY, id);
        }
        else
            return super.setVariable(key, value);

    }

}
